﻿#region Imports
using System;
using System.Globalization;
using System.Windows.Data;
using CommonUtilities.Extensions;
using CommonUtilities.Properties;
using EntertainmentManager.Models;
#endregion

namespace EntertainmentManager.Converters
{
    public class ImdbUrlConverter : IValueConverter
    {
        string baseUrl = "http://www.imdb.com";

        #region IValueConverter Members
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            EpisodeInfo ep;
            try { ep = (EpisodeInfo)value; }
            catch (Exception) { return ""; }

            string reference = (parameter as string == "S" ? ep.SeriesTitle : ep.EpisodeTitle);
            if (reference.IsNullOrEmpty()) return Resources.Const_NotAvailable;

            return baseUrl + (ep.ImdbUrl.IsNullOrEmpty()
                ? "?q=" + reference.RestoreStringArticles().Replace(" ", "+")
                : ep.ImdbUrl);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();

            //EpisodeInfo ep;
            //try { ep = (EpisodeInfo)value; }
            //catch (Exception) { throw; }
            //
            //if (ep.Contains())
            //{
            //  
            //}
            //
            //return baseUrl + (ep.ImdbUrl.IsNullOrEmpty()
            //    ? "?q=" + FormatStringArticles(parameter as string == "S" ? ep.SeriesTitle : ep.EpisodeTitle).Replace("+", " ")
            //    : ep.ImdbUrl);
        }
        #endregion
    }
}
